package com.bincloud.vue.admin.web.controller.ums;


import com.alibaba.fastjson.JSON;
import com.bincloud.vue.admin.common.model.dto.response.BaseResDTO;
import com.bincloud.vue.admin.common.util.ResponseUtils;
import com.bincloud.vue.admin.web.dto.ums.user.role.UmsUserRoleRelationReqDTO;
import com.bincloud.vue.admin.web.service.ums.IUmsUserRoleRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bincloud, mvpzhou
 * @since 2022-02-17
 */
@Api(tags = "用户角色关系相关接口")
@RestController
@RequestMapping("/admin/ums/userRoleRelation")
@Slf4j
public class UmsUserRoleRelationController {
    @Resource
    private IUmsUserRoleRelationService umsUserRoleRelationService;

    @PreAuthorize(value = "hasAuthority('admin:ums:user')")
    @ApiOperation(value = "用户角色关系绑定", produces = "application/json")
    @PostMapping(value = "/bind")
    public BaseResDTO<Boolean> bind(@Validated @RequestBody UmsUserRoleRelationReqDTO reqDTO) {
        log.info("用户角色关系绑定,入参:{}", JSON.toJSONString(reqDTO));
        boolean resDTO = umsUserRoleRelationService.bind(reqDTO);
        log.info("用户角色关系绑定,返参:{}", JSON.toJSONString(resDTO));
        return ResponseUtils.ok();
    }

    @PreAuthorize(value = "hasAuthority('admin:ums:user')")
    @ApiOperation(value = "用户角色关系解除", produces = "application/json")
    @PostMapping(value = "/lift")
    public BaseResDTO<Boolean> lift(@Validated @RequestBody UmsUserRoleRelationReqDTO reqDTO) {
        log.info("用户角色关系解除,入参:{}", JSON.toJSONString(reqDTO));
        boolean resDTO = umsUserRoleRelationService.lift(reqDTO);
        log.info("用户角色关系解除,返参:{}", JSON.toJSONString(resDTO));
        return ResponseUtils.ok();
    }

}

